from UserInterface.InvokeInstruction import InvokeInstruction
from UserInterface.InvokeInstruction import invoke_auto_add
from UserInterface.InvokeInstruction import GetInvokeInstTable

@invoke_auto_add
class PrintHelpInvoke(InvokeInstruction):
    def __init__(self) -> None:
        super().__init__()
        self.instSymbol:str = 'h'
        self.helpInfo:str = 'print help information'
        self.args:str = ''

    def Execute(self, *args) -> None:
        helpStr = ''
        helpStr += '========== HELP ==========\n'
        helpStr += 'options Info:\n'
        invokeInstTable = GetInvokeInstTable()
        for item in invokeInstTable:
            helpStr += invokeInstTable[item].GetHelp()
            helpStr += '\n'
        self.logger.print(helpStr)

@invoke_auto_add
class DemoCmd(InvokeInstruction):
    def __init__(self) -> None:
        super().__init__()
        self.instSymbol:str = 'd'
        self.helpInfo:str = 'DemoCmd'
        self.args:str = ''

    def Execute(self, *args) -> None:
        self.logger.Info('this is demo')

@invoke_auto_add
class InvokeTUI(InvokeInstruction):
    tuiApi = None
    def __init__(self) -> None:
        super().__init__()
        self.instSymbol:str = 't'
        self.helpInfo:str = 'TUI'
        self.args:str = ''

    def Execute(self, *args) -> None:
        InvokeTUI.tuiApi()

    @classmethod
    def SetTUIEntry(cls, tuiApi):
        cls.tuiApi = tuiApi

@invoke_auto_add
class InvokeTUIBatch(InvokeInstruction):
    tuiApi = None
    def __init__(self) -> None:
        super().__init__()
        self.instSymbol:str = 'b'
        self.helpInfo:str = 'TUI batch mode'
        self.args:str = '<fileName>'

    def Execute(self, *args) -> None:
        InvokeTUIBatch.tuiApi(args[0][0])

    @classmethod
    def SetTUIEntry(cls, tuiApi):
        cls.tuiApi = tuiApi